@echo off
@rem *** 
@rem *** This script sets up IISExpress for the given web application
@rem *** Set values for COMPUTERNAME and USERNAME comparison to ensure this is run
@rem *** in the correct environment (or remove those tests)
@rem *** This must be run as administrator
@rem ***
@rem *** Update 
@rem *** 
@echo Computer: "%COMPUTERNAME%" - User: "%USERNAME%"
@if not "%COMPUTERNAME%" == "RGWSVW7-103" goto WrongCompOrUser
@if not "%USERNAME%" == "BillG" goto WrongCompOrUser
@echo.

@SETLOCAL

@rem *** Update this section for individual application
Set DNSName=test.rgwsvw7103.local
Set HttpPort=35080
Set HttpLHPort=35180
Set HttpsPort=35443
Set WebAppName=CodeCamp
@rem ***

Set AppId={214124cd-d05b-4309-9af9-9caa44b2b74a}
Set SertHash=916f26a634299583df7de09d1f797da9e863ae9a
Set IPPort=0.0.0.0:%HttpsPort%

Set URL=http://%DNSName%:%HttpPort%/
Set URLLH=http://localhost:%HttpLHPort%/
Set URLS=https://%DNSName%:%HttpsPort%/
Set TempFile=%temp%\IISExp_Setup_Temp.txt

GOTO CertFound
@rem ********************
@echo on
netsh http show sslcert ipport=%IPPort%	>"%TempFile%"
@echo off

find "IP:port                 : %IPPort%" "%TempFile%"
@If %ERRORLEVEL% == 1 Goto CertNotFound
@goto CertFound

:CertNotFound
@echo.**********
@echo Cert for port "%IPPort%" NOT FOUND
@echo.
@echo Add Cert configuration?
@echo.
@echo.**********
@pause
@echo.

@echo on
netsh http add sslcert ipport=%IPPort% appid=%AppId% certhash=%SertHash%
@if ERRORLEVEL == 1 goto CertAddError
@echo off

:CertFound

@rem ********************
@echo on
netsh http  show urlacl Url=%URL% >"%TempFile%"
@echo off
find "%URL%" "%TempFile%"
@If %ERRORLEVEL% == 1 Goto URLNotFound
@goto URLFound

:URLNotFound
@echo.**********
@echo URL "%URL%" NOT FOUND
@echo.
@echo Add URL configuration?
@echo.
@echo.**********
@pause

@echo on
netsh http add urlacl url=%URL% user=Everyone
@if ERRORLEVEL == 1 goto UrlAddError
@echo off

:URLFound
@echo.
GOTO URL2Found

@rem ********************
@echo on
netsh http  show urlacl Url=%URLS% >"%TempFile%"
@echo off
find "%URLS%" "%TempFile%"
@If %ERRORLEVEL% == 1 Goto URL2NotFound
@goto URL2Found

:URL2NotFound
@echo.**********
@echo URL "%URLS%" NOT FOUND
@echo.
@echo Add URL configuration?
@echo.
@echo.**********
@pause

@echo on
netsh http add urlacl url=%URLS% user=Everyone
@if ERRORLEVEL == 1 goto Url2AddError
@echo off

:URL2Found
@echo.

@rem ********************


@goto End



:WrongCompOrUser
@echo *** Invalid computer or user
@goto End

:CertAddError
@echo *** Error adding certificate
@goto End

:UrlAddError
@echo *** Error adding HTTP URL
@goto End

:Url2AddError
@echo *** Error adding HTTPS URL
@goto End


:End

@ENDLOCAL

